package com.jtjrenren.android.taxi.driver.core.wallect;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.jtjrenren.android.taxi.driver.Constants;
import com.jtjrenren.android.taxi.driver.R;
import com.jtjrenren.android.taxi.driver.bean.DriverInfo;
import com.jtjrenren.android.taxi.driver.manger.AppManger;

import com.jtjrenren.android.taxi.driver.bean.api.ApiPocketInfo;
import com.jtjrenren.android.taxi.driver.base.BaseActivity;
import com.jtjrenren.android.taxi.driver.manger.api.ApiWorks;
import com.jtjrenren.android.taxi.driver.utils.IntentUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/5/5.
 */
public class WallectActivity extends BaseActivity {
    @BindView(R.id.wallect_ye)
    TextView tv_ye;
    @BindView(R.id.wallect_zsr)
    TextView tv_zsr;
    @BindView(R.id.wallect_ztq)
    TextView tv_ztq;
    @BindView(R.id.wallect_wdz)
    TextView tv_wdz;
    @BindView(R.id.wallect_xscon)
    LinearLayout ll_xscon;
    @BindView(R.id.wallect_txcon)
    LinearLayout ll_txcon;
    @BindView(R.id.wallect_wdz_con)
    LinearLayout ll_wdzcon;

    DriverInfo driver;

    @Override
    public int getLayoutID() {
        return R.layout.aty_wallect;
    }

    @Override
    public void init() {
        driver = AppManger.getInstance().driver;
        ((TextView) findViewById(R.id.title_title)).setText("钱包账户");
        findViewById(R.id.title_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        ll_wdzcon.setVisibility(View.GONE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        getPocketInfo();
    }

    @OnClick(R.id.wallect_qtx)
    public void clickTx(){
        ll_xscon.setVisibility(View.GONE);
        ll_txcon.setVisibility(View.VISIBLE);
        ll_wdzcon.setVisibility(View.VISIBLE);
    }

    @OnClick(R.id.wallect_srmx)
    public void clickSrmx(){
        IntentUtils.goSrHistoryPage(this);
    }

    @OnClick(R.id.wallect_txmx)
    public void clickTxmx(){
        IntentUtils.goTxHistoryPage(this);
    }

    @OnClick(R.id.wallect_txdzfb)
    public void clickTxzfb(){
        IntentUtils.goTxPage(this, Constants.TYPE_PAY_ZFB);
    }

    @OnClick(R.id.wallect_txdyhk)
    public void clickTxyhk(){
        IntentUtils.goTxPage(this, Constants.TYPE_PAY_YHK);
    }

    private void refreshView(ApiPocketInfo.MsgEntity msg) {
        if (AppManger.getInstance().driver != null)
            AppManger.getInstance().driver.setRMBMoney(msg.getRMBMoney());

        tv_ye.setText(msg.getRMBMoney());
        tv_zsr.setText(msg.getIncome());
        tv_ztq.setText(msg.getTradeFair());
        tv_wdz.setText(msg.getNodoneTixian());
    }


    private void getPocketInfo() {
        if (driver == null)
            return;
        showProDialog(null, getString(R.string.shuaxinshujuqingshaohou));
        ApiWorks.getDriverPocketInfo(driver.getWorkNo(), new ApiWorks.ResponseListener<ApiPocketInfo>() {
            @Override
            public void onResponse(ApiPocketInfo apiPocketInfo) {
                disProDialog();
                if (apiPocketInfo != null && "SM0013".equals(apiPocketInfo.getResult())) {
                    //查询成功
                    refreshView(apiPocketInfo.getMsg());
                }
            }
        });
    }
}
